(function(){BX.namespace("BX.Rest.Configuration.Export");if(!BX.Rest.Configuration.Export){return}function t(){}t.prototype={init:function(t){this.next="";this.section=[];this.errors=[];this.id=t.id;this.signedParameters=t.signedParameters;BX.bind(BX.findChildByClassName(BX(this.id),"start-btn"),"click",BX.delegate((function(t){this.start()}),this))},start:function(){BX.addClass(BX.findChildByClassName(BX(this.id),"rest-configuration-start-icon-main"),"rest-configuration-start-icon-main-loading");BX.style(BX.findChildByClassName(BX(this.id),"start-btn-block"),"display","none");BX.insertAfter(BX.create("div",{attrs:{className:"rest-configuration-info"},children:[BX.create("p",{attrs:{className:""},text:BX.message("REST_CONFIGURATION_EXPORT_START_DESCRIPTION")})]}),BX.findChildByClassName(BX(this.id),"rest-configuration-info"));BX.findChildByClassName(BX(this.id),"rest-configuration-info").remove();this.sendAjax("start",{},BX.delegate((function(t){if(t.data.length>0){this.section=t.data;this.loadManifest(0,"")}else{this.showFatalError()}}),this))},loadManifest:function(t,i){this.sendAjax("loadManifest",{step:t,next:i},BX.delegate((function(i){if(!!i.data){t++;if(i.data.next===false){this.load(0,0)}else{this.loadManifest(t,i.data.next)}}else{this.showFatalError()}}),this))},load:function(t,i){this.sendAjax("load",{code:this.section[t],step:i,next:this.next},BX.delegate((function(a){if(!!a.data){this.next=a.data.next;i++;if(this.next===false){t++;i=0}if(t>=this.section.length){this.finish()}else{this.load(t,i)}}else{this.showFatalError()}}),this))},finish:function(){this.sendAjax("finish",{},BX.delegate((function(t){if(!!t.data.result&&t.data.result===true){this.showFinish(t)}else{this.finish()}console.log("ajax:",t)}),this))},showFinish:function(t){var i=BX.findChildByClassName(BX(this.id),"rest-configuration-start-icon-main");var a=BX.findChildByClassName(BX(this.id),"rest-configuration-info");BX.removeClass(i,"rest-configuration-start-icon-main-zip rest-configuration-start-icon-main-loading");var e="";if(!!t.data&&!!t.data.download){e=t.data.download}var s="";if(this.errors.length===0&&e!==""){s=BX.message("REST_CONFIGURATION_EXPORT_FINISH_DESCRIPTION");BX.addClass(i,"rest-configuration-start-icon-main-success")}else{s=BX.message("REST_CONFIGURATION_EXPORT_FINISH_ERROR_DESCRIPTION");BX.addClass(i,"rest-configuration-start-icon-main-error")}BX.cleanNode(a);a.appendChild(BX.create("p",{attrs:{className:""},text:s}));if(e!==""){a.appendChild(BX.create("a",{attrs:{className:"ui-btn ui-btn-lg ui-btn-primary start-btn",href:e,"data-slider-ignore-autobinding":"true"},text:BX.message("REST_CONFIGURATION_DOWNLOAD_BTN")}))}if(this.errors.length!==0){a.appendChild(BX.create("div",{attrs:{className:"rest-configuration-links"},children:[BX.create("a",{attrs:{"data-slider-ignore-autobinding":"true",href:""},events:{click:BX.delegate(this.openPopupErrors,this)},text:BX.message("REST_CONFIGURATION_EXPORT_ERRORS_REPORT_BTN")})]}))}},sendAjax:function(t,i,a){BX.ajax.runComponentAction("bitrix:rest.configuration.export",t,{mode:"class",signedParameters:this.signedParameters,data:i}).then(BX.delegate((function(e){if(!!e.data.exception){this.showFatalError(e.data.exception)}else{a(e)}if(!!e.data.errors){this.addErrors(e.data.errors)}if(!!e.data["errorsNotice"]){console.log({errors:e.data["errorsNotice"],action:t,data:i,response:e})}}),this)).catch(function(t){this.showFatalError()}.bind(this))},addErrors:function(t){for(var i=0;i<t.length;i++){this.errors.push(t[i])}},showFatalError:function(t){var i="";var a=BX.findChildByClassName(BX(this.id),"rest-configuration-info");var e=BX.findChildByClassName(BX(this.id),"rest-configuration-start-icon-main");BX.removeClass(e,"rest-configuration-start-icon-main-zip rest-configuration-start-icon-main-loading");BX.addClass(e,"rest-configuration-start-icon-main-error");if(t.length>0){for(var s=0;s<t.length;s++){if(i!==""){i+="\n"}i=t[s].message}}else if(BX.type.isString(t)){i=t}BX.cleanNode(a);a.appendChild(BX.create("div",{attrs:{className:"rest-configuration-fatal-error-block"},children:[],text:i!==""?i:BX.message("REST_CONFIGURATION_FATAL_ERROR")}))},openPopupErrors:function(){var t="";this.errors.forEach((function(i){t+=i+"\r\n"}));var i=BX.create("textarea",{props:{className:"rest-configuration-popup-textarea",placeholder:BX.message("REST_CONFIGURATION_EXPORT_ERRORS_POPUP_TEXT_PLACEHOLDER")},html:t});var a=BX.create("div",{children:[BX.create("div",{props:{className:"rest-configuration-popup-textarea-title"},text:BX.message("REST_CONFIGURATION_EXPORT_ERRORS_POPUP_TEXT_LABEL")}),i]});var e=BX.PopupWindowManager.create("rest-configuration-popup",null,{className:"rest-configuration-popup",titleBar:BX.message("REST_CONFIGURATION_EXPORT_ERRORS_POPUP_TITLE"),content:a,contentBackground:"transparent",contentPadding:10,minWidth:250,maxWidth:450,autoHide:true,closeIcon:true,animation:"fading-slide",buttons:[new BX.UI.Button({text:BX.message("REST_CONFIGURATION_EXPORT_ERRORS_POPUP_BTN_COPY"),color:BX.UI.Button.Color.LINK,events:{click:function(){i.select();document.execCommand("copy")}}})],onPopupClose:function(){this.destroy()}});e.show()}};BX.Rest.Configuration.Export=new t})(window);
//# sourceMappingURL=script.map.js